package com.wei.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wei.entity.GdParking;
import com.wei.mapper.GdParkingMapper;
import com.wei.mapper.GdParkingMapper;
import com.wei.mapper.GdPropertyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 李泽伟
 * @since 2022-03-08
 */
@RestController
@RequestMapping
public class GdParkingController {

    @Autowired
    private GdParkingMapper parkingMapper;

    @RequestMapping("/getParking")
    public List<GdParking> getParking(){
        Map<String, Object> map = new HashMap<>();
        map.put("deleted", 0);
        return parkingMapper.selectByMap(map);
    }

    @RequestMapping("/addParking")
    public void setParking(@RequestParam Map<String,Object> parkingObj){
        GdParking parking =setParam(parkingObj);
        parkingMapper.insert(parking);
    }

    @RequestMapping("/updateParking")
    public void updateParking(@RequestParam Map<String,Object> parkingObj){
        GdParking parking = setParam(parkingObj);
        parkingMapper.updateById(parking);
    }

    @RequestMapping("/deleteParking")
    public void deleteParking(@RequestParam String parkingId){
        parkingMapper.deleteById(parkingId);
    }

    /**
     * 设置参数方法
     * @param parkingObj
     * @return
     */
    private GdParking setParam(@RequestParam Map<String, Object> parkingObj) {
        GdParking parking=new GdParking();
        parking.setParkingId((String) parkingObj.get("parkingId"));
        parking.setParkingAddress((String) parkingObj.get("parkingAddress"));
        parking.setParkingIssell((String) parkingObj.get("parkingIssell"));
        parking.setParkingForeignkey((String) parkingObj.get("parkingForeignkey"));
        parking.setParkingBuydate((String) parkingObj.get("parkingBuydate"));
        parking.setParkingBuytime(Integer.parseInt(parkingObj.get("parkingBuytime").toString()));
        parking.setParkingCarnum((String) parkingObj.get("parkingCarnum"));
        parking.setHouseholdName((String) parkingObj.get("householdName"));
        parking.setPropertyAddress((String) parkingObj.get("propertyAddress"));
        return parking;
    }

}

